// pages/index/consultation_reservation/reservation/reservation.js
const app = getApp()
Page({
  data: {
    url: '',
    consultList: '',
    typeId: '',
    levelId: ''
  },
  godetail(e) {
    const detail = e.currentTarget.dataset.detail;
    // 封装 details
    const dataToSend = {
      data: {
        img: detail.img, 
        name: detail.name,
        studioCity: detail.studioCity || '未知城市',
        level: detail.level || 0,
        id: detail.id 
      }
    };
    wx.navigateTo({
      url: '/pages/zixun/Details/details',
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', dataToSend);
      }.bind(this)
    });
  },
  /**
   * 生命周期函数 -- 监听页面加载
   */
  onLoad(options) {
    this.setData({
      url: app.globalData.URL
    });
    const that = this;
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('onlineDetail', function (data) {
      that.setData({
        typeId: data.typeId,
        levelId: data.levelId
      });
      wx.request({
        url: that.data.url + '/consult/selectByLevelIdAndTypeId',
        method: 'GET',
        data: {
          levelId: that.data.levelId,
          typeId: that.data.typeId
        },
        success(resp) {
          that.setData({
            consultList: resp.data.data
          });
        }
      });
    });
  }
});